<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Symbol概述</title>
</head>
<body>
    <h1>Symbol概述</h1>
    <h2>Symbol是JavaScript的第七种数据类型，表示独一无二的值</h2>

    <script>
        // 创建Symbol
        let s1 = Symbol();
        let s2 = Symbol();
        console.log(s1 === s2); // false

        // Symbol带描述的创建
        let s3 = Symbol('foo');
        let s4 = Symbol('foo');
        console.log(s3 === s4); // false
        
        // Symbol不能与其他类型的值进行运算
        // console.log(Symbol() + 'hello'); // TypeError

        // Symbol可以转为字符串
        let sym = Symbol('My symbol');
        console.log(String(sym)); // 'Symbol(My symbol)'
        console.log(sym.toString()); // 'Symbol(My symbol)'
    </script>
</body>
</html> 